<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function SuperType() {
        this.name = "aaa";
        this.color = ["red", "green", "yellow"];
      }

      SuperType.prototype.sayHi = function () {
        console.log("hello" + this.name);
      };


      function SubType(name = "moren", age = 10) {
        // 自生自带的属性
        this.name = name;
        this.age = age;
      }

      // 当然不能这么写，这样写直接引用的是同一个原型，子原型改变，父原型也会改变
      SubType.prototype = SuperType.prototype

      // 继承后写自身原型的方法
      SubType.prototype.walk = function () {
        console.log("走路");
      };

      let obj1 = new SubType();
      let obj2 = new SubType("bbb", 30);
      console.log(SubType.prototype);
      console.log(obj1.__proto__ === SubType.prototype);
      console.log(obj1.color);
      obj1.sayHi();
      obj1.walk();
      obj2.sayHi();
    </script>
  </body>
</html>
